package cn.bdqn.repository;

import cn.bdqn.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
    @Query("from User where usrRoleId=:roleId")
    //@Query("from User where usrRoleId=?1")
    public List<User> findByRoleIdByHQL(Long roleId);
    @Query("update User set usrName=?1 where usrId=?2")
    @Modifying
    @Transactional
    public void updateUserByHQL(String usrName, Long usrId);

    @Query(value = "select * from sys_user where usr_role_id=?1", nativeQuery = true)
    public List<User> findByRoleIdBySQL(Long roleId);

    public List<User> findByUsrName(String usrName);

    public List<User> findByUsrNameLike(String usrName);

    public List<User> findByUsrNameAndUsrPassword(String usrName, String usrPassword
    );
}

